package com.example.japinhands.ui.screen

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import com.example.japinhands.JapViewModel
import com.example.japinhands.MainActivity

@Composable
fun TestManageWordScreen(
    viewModel: JapViewModel
) {
    val activity = LocalContext.current as MainActivity
//    val wordListUI by viewModel.wordsLiveData.observeAsState()

//    viewModel.getAllWords()

//    viewModel.setOnGetListenerAndGetAllWords { words ->
//        wordList.addAll(words)
//        wordList.forEach { word ->
//            viewModel.setOnQueryListenerAndQuerySentenceById(word.id) {
//                word.sentenceContent = it.content
//            }
//        }
//    }

    LaunchedEffect(Unit) {
        viewModel.getAllWords()
    }

    DisposableEffect(Unit) {
        onDispose {
            viewModel.clearWords()
        }
    }



    LazyColumn {
        viewModel.wordsUI.forEach {
            item {
                JapaneseWordCardTest(
                    word = it,
//                    sentence = it.sentenceContent,
                    onClick = {}
                )
            }
        }
    }
}